
source bin/xsmack-lib.tcl

if { [ llength $argv ] != 1 } {
    puts "Need bound!"
    exit 1
}
set bound $argv

array_read_cols stdin A { 0 1 }

array set D {}
set N [ array size A ]
for { set i 0 } { $i < $N } { incr i } {
    set L $A($i)
    set v [ lindex $L 1 ]
    set D($i) $v
}

array set R {}

for { set i 0 } { $i < $N } { incr i } {
    set p [ expr min($i,$bound) ]
    set q [ expr min($N-$i-1,$bound) ]
    set C [ expr $p + $q + 1 ]

    # show i p q

    set sum 0
    set z [ expr $i + $q ]
    for { set j [ expr $i - $p ] } { $j <= $z } { incr j } {
        # show D($j)
        set sum [ expr $sum + $D($j) ]
    }
    set avg [ expr $sum / $C ]
    # show sum C avg
    set R($i) $avg
    # puts "---"
}

# array_fprintf_int stdout "%s %s" R
array set T {}
for { set i 0 } { $i < $N } { incr i } {
    set L $A($i)
    set k [ lindex $L 0 ]
    set T($k) $R($i)
}
array_fprintf_dbl stdout "%s %s" T
